﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace ModelChecking.ModelValidation.LongitudinalModel
{
	public partial class MainForm : System.Windows.Forms.Form
	{
		public bool IsByCurrentFloorSelect
		{
			get
			{
				return this.rdbBySelect.Checked;
			}
		}

		public CheckingTypeStates GetCheckingTypeStatesInfo
		{
			get
			{
				return this.m_CheckingTypeStatesInfo;
			}
		}

		public MainForm()
		{
			this.InitializeComponent();
		}

		private void MainForm_Load(object sender, EventArgs e)
		{
			//base.Icon = Resource.YArchitechIcon;
			this.ReadData();
		}

		private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (base.DialogResult != DialogResult.OK)
			{
				return;
			}
			this.m_CheckingTypeStatesInfo = SettingForm.GetCheckingTypeStates();
			this.SaveData();
		}

		private void ReadData()
		{
			string tempPath = Path.GetTempPath();
			string path = tempPath + "LongitudinalModelCheckingMainForm.dat";
			if (!File.Exists(path))
			{
				base.StartPosition = FormStartPosition.CenterScreen;
				this.rdbBySelect.Checked = true;
				this.rdbByFloors.Checked = false;
				return;
			}
			base.StartPosition = FormStartPosition.Manual;
			FileStream fileStream = new FileStream(path, FileMode.Open);
			StreamReader streamReader = new StreamReader(fileStream);
			streamReader.BaseStream.Seek(0L, SeekOrigin.Begin);
			int x = Convert.ToInt32(streamReader.ReadLine());
			int y = Convert.ToInt32(streamReader.ReadLine());
			base.Location = new Point(x, y);
			this.rdbBySelect.Checked = Convert.ToBoolean(streamReader.ReadLine());
			this.rdbByFloors.Checked = Convert.ToBoolean(streamReader.ReadLine());
			streamReader.Close();
			fileStream.Close();
		}

		private void SaveData()
		{
			string tempPath = Path.GetTempPath();
			string path = tempPath + "LongitudinalModelCheckingMainForm.dat";
			FileStream fileStream = new FileStream(path, FileMode.Create);
			StreamWriter streamWriter = new StreamWriter(fileStream);
			streamWriter.WriteLine(base.Location.X);
			streamWriter.WriteLine(base.Location.Y);
			streamWriter.WriteLine(this.rdbBySelect.Checked);
			streamWriter.WriteLine(this.rdbByFloors.Checked);
			streamWriter.Flush();
			streamWriter.Close();
			fileStream.Close();
		}

		private void btnSetting_Click(object sender, EventArgs e)
		{
			SettingForm settingForm = new SettingForm();
			if (settingForm.ShowDialog() == DialogResult.OK)
			{
				this.m_CheckingTypeStatesInfo = SettingForm.GetCheckingTypeStates();
			}
		}

		private CheckingTypeStates m_CheckingTypeStatesInfo = new CheckingTypeStates();
	}
}
